package main

import (
	"fmt"
	"reflect"
)

func main() {
	//获取类型信息
	var x float64 = 3.4
	fmt.Println("type:", reflect.TypeOf(x))
	v := reflect.ValueOf(x)
	fmt.Println("type:", v.Type())
	fmt.Println("kind is float64:", v.Kind() == reflect.Float64)
	fmt.Println("value:", v.Float())
	fmt.Println("settability of v:", v.CanSet()) //当CanSet返回false时，不应该去调用set方法
	fmt.Println("kind:", v.Kind())

	fmt.Println("-----------------获取值类型---------------")

	p := reflect.ValueOf(&x) //调用valueof方法都时候，会生成一个副本
	fmt.Println("type of p:", p.Type())
	fmt.Println("settability of p:", p.CanSet())
	v1 := p.Elem() //返回指针
	fmt.Println("settability of v:", v1.CanSet())
	v1.SetFloat(7.1)
	fmt.Println(v1.Interface())
	fmt.Println(x)

}
